#include "logger/logger.h"
#include "timer/timer_manager.h"
#include <catch2/catch_test_macros.hpp>
#include <chrono>
#include <thread>

TEST_CASE("Timer", "[timer]")
{
    using namespace zh;

    TimerManager timers;
    auto         hello = []() { LOG_WARN("hello timer"); };

    int id  = timers.addTimer(0, hello);
    int id2 = timers.addTimer(1000, hello);
    int id3 = timers.addTimer(3000, hello);
    int id4 = timers.addTimer(6000, hello);

    REQUIRE(timers.findTimer(id) == true);
    timers.run();
    REQUIRE(timers.findTimer(id) == false);
    timers.removeTimer(id3);
    using namespace std::chrono_literals;
    std::this_thread::sleep_for(5000ms);
    timers.run();
    REQUIRE(timers.getTimerCount() == 1);
}
